<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" MasterPageFile="~/Views/Shared/Iframe.Master" %>

<asp:Content ID="cJScripts" ContentPlaceHolderID="cphJScripts" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {

            $('#imageCrop img').Jcrop({
                onSelect: storeCoords,
                aspectRatio: 1,
                minSize: [130, 130]
            });

            // load
            $(window).bind("load", function () {
                resize();
            });

            $("#submit").click(function () {
                if ($("span input.check[value!=0][value!='']").length > 0) {
                    $.ajax({
                        type: "POST",
                        url: '/<%= ViewData["SystemName"] %>/Staff/AdminStaffImageCrop',
                        data: 'X=' + $("#X").val() + '&Y=' + $("#Y").val() + '&W=' + $("#W").val() + '&H=' + $("#H").val(),
                        success: function (msg) {
                            parent.$.fn.colorbox.close();
                            parent.insertCroppedImage();
                        },
                        error: function () {
                            parent.$.fn.colorbox.close();
                        }
                    });
                } else {
                    $("#error").show("fast", function () {
                        resize()
                    });
                }
            });
        });

        function resize() 
        {
            var iOffSet = ($.browser.msie) ? 0 : 20;
            var iW = $(document).width();
            var iH = $(document.body).height() + iOffSet;
            
            // adjust size
            parent.$.fn.colorbox.myResize(iW, iH);
        }

        function storeCoords(c) {
            $("#error").hide("fast", function () {
                resize()
            });
            $('#X').val(c.x);
            $('#Y').val(c.y);
            $('#W').val(c.w);
            $('#H').val(c.h);
        };
    </script>
</asp:Content>

<asp:Content ID="cMainContent" ContentPlaceHolderID="cphMainContent" runat="server">
    <div id="contentPage">
        <div id="head">
            <a href="javascript:void(0);" class="mediumBtn green awesome" id="submit">Confirmer</a>
            <%= ScoutNET.Resources.Staff_ImageCrop_Intro %>
            <hr />
            <div id="error" class="hide">
                <span class="validation-summary-errors"><%= ScoutNET.Resources.Master_Form_ErrorMessage %></span>
                <ul class="validation-summary-errors">
                    <li><%= ScoutNET.Resources.Staff_ImageCrop_Error_NoCrop %></li>
                </ul>
            </div>
        </div>
        <div id="imageCrop"><img src="/<%= ViewData["SystemName"] %>/Staff/AdminStaffImageResize/<%= ViewData["DefaultImageId"] %>" alt="" /></div>
        <span>
            <%=Html.Hidden("X", "")%>
            <%=Html.Hidden("Y", "")%>
            <%=Html.Hidden("W", "", new { @class = "check" })%>
            <%=Html.Hidden("H", "", new { @class = "check" })%>
        </span>
    </div>
</asp:Content>